//操作cookie的文件
//定义操作cookie的方法
/**
 * 入参接收key，出参返回对应value值，如果不存在该key值，则返回undefined
 */
window.getCookie = window.getCookie || function (key) {
    let cookieArray = document.cookie.split("; ");
    for (let item of cookieArray) {
        if (item.split("=")[0] === key) {
            return item.split("=")[1];
        }
    }
}

window.setCookie = window.setCookie || function (key, value, expires, path) {
    let date;
    if (expires && expires instanceof Date) {
        date = expires;
    } else {
        // let d = new Date();
        date = new Date().setDate(new Date().getDate() + 30);
    }
    console.log(`${encodeURIComponent(key)}=${encodeURIComponent(value)};expires=${date}`);
    document.cookie = `${encodeURIComponent(key)}=${encodeURIComponent(value)};expires=${date}`;
}